<?php

namespace lxs\tools;
use Carbon\Carbon;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use lxs\config\BaseStatic;


class Uploads extends BaseStatic
{

    /**
     * 本地上传
     */
    public function localUpload($file, $path = ''): bool|string
    {
        if (is_file($file)) {
            $path = $path == '' ? 'local' : $path;
            $path = $path . '/' . Carbon::now()->format('Ymd');
            $fileName = Str::random(32) . '.' . $file->getClientOriginalExtension();
            if (Storage::disk('public')->put($path . '/' . $fileName, file_get_contents($file))) {
                return '/storage/' . $path . '/' . $fileName;
            }
            return false;
        }
        return false;
    }


}
